  <!DOCTYPE html>
  <html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../../lib/layui-v2.8.12/src/layui.js"></script>
    <link rel="stylesheet" href="../../lib/layui-v2.8.12/src/css/layui.css">
    <link rel="stylesheet" href="../../css/team/addTeam.css">
    <script src="../../utils/form-serialize.js"></script>
    <script src="../../lib/axios/axios.min.js"></script>
  </head>

  <body>

  </body>

  </html>
  <?php
  DEFINE('DB_USER', 'worldcup');
  DEFINE('DB_PASSWORD', '123456');
  DEFINE('DB_HOST', 'localhost');
  DEFINE('DB_NAME', 'worldcup');

  $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  if (!$dbc) {
    die('Could not to connect to Mysql:' . mysqli_connect_error());
  }
  mysqli_set_charset($dbc, 'utf8');
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $teamName = $_POST['teamName'];
    $coach = $_POST['coach'];
    $playerId = $_POST['playerId'];
    $teamDesc = $_POST['teamDesc'];
    $worldRank = $_POST['worldRank'];
    $winRate = $_POST['winRate'];
    $wins = $_POST['wins'];
    $draws = $_POST['draws'];
    $fails = $_POST['fails'];
    $goals = $_POST['goals'];
    $teamId = $_GET['teamId'];


    $sqlUpdate = "update team set team_name='{$teamName}',world_rank=$worldRank,wins=$wins,draws=$draws,fails=$fails,goals=$goals,coach='{$coach}',win_rate=$winRate,team_desc='{$teamDesc}',best_player_id=$playerId where team_id=$teamId;";

    $resUpdate = mysqli_query($dbc, $sqlUpdate);
    if (!$resUpdate) {
      printf("Error: %s\n", mysqli_error($dbc));
      exit();
    }
    // echo $resUpdate;
    echo '<script>';
    if ($resUpdate == 1) {
      $sql1 = "call update_point ();";
      $sql2 = "call update_rank();";
      $res1 = mysqli_query($dbc, $sql1);
      $res2 = mysqli_query($dbc, $sql2);
      echo '
        layui.use(\'layer\', function() {
          var layer = layui.layer;
          layer.msg(\'修改球队成功，请刷新页面\');
          setTimeout(() => {
            var index = parent.layer.getFrameIndex(window.name); // 获取弹出层索引
            parent.layer.close(index); // 关闭弹出层
          }, 2000);
        });
      ';
    } else {
      echo '
        layui.use(\'layer\', function() {
          var layer = layui.layer;
          layer.msg(\'修改球队失败\');
          setTimeout(() => {
            var index = parent.layer.getFrameIndex(window.name); // 获取弹出层索引
            parent.layer.close(index); // 关闭弹出层
          }, 2000);
        });
      ';
    }
    echo '</script>';
  }
  ?>